package com.study.prototype.shallow;

import com.study.prototype.general.IPrototype;

import java.util.List;

/**
 * 浅克隆
 * 通过JDK自带的Cloneable接口实现
 * 性能优良 基于内存二进制流的拷贝 比直接new一个对象性能好
 * 只能实现基本数据类型、String的克隆  数组集合等不能克隆
 */
public class ConcretePrototype implements Cloneable {

    private String name;
    private int age;
    private List<String> hobbies;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public List<String> getHobbies() {
        return hobbies;
    }

    public void setHobbies(List<String> hobbies) {
        this.hobbies = hobbies;
    }

    @Override
    public ConcretePrototype clone() {
        try {
            return (ConcretePrototype) super.clone();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String toString() {
        return "ConcretePrototype{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", hobbies=" + hobbies +
                '}';
    }
}
